Skip to content

Don't create unmet demand file unless needed.#1405

Open
dalonsoa wants to merge 5 commits into
mainfrom
1372_unmet_demand_file
Open

Don't create unmet demand file unless needed.#1405
dalonsoa wants to merge 5 commits into
mainfrom
1372_unmet_demand_file

Conversation

@dalonsoa

@dalonsoa dalonsoa commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Description

The path for the file is added to the structure, keeping the actual writer as an option and only created if needed. A check is added to verify that the writer does not exist, which would mean that the run did not stopped after finding unmet demand. The file is closed alongside all the other files, if needed. The regression tests files for the simple case has been amended to removed the empty file, not needed anymore.

Fixes #1372

Type of change

  • Bug fix (non-breaking change to fix an issue)
  • New feature (non-breaking change to add functionality)
  • Refactoring (non-breaking, non-functional change to improve maintainability)
  • Optimization (non-breaking change to speed up the code)
  • Breaking change (whatever its nature)
  • Documentation (improve or add documentation)

Key checklist

  • All tests pass: $ cargo test
  • The documentation builds and looks OK: $ cargo doc
  • Update release notes for the latest release if this PR adds a new feature or fixes a bug
    present in the previous release

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@dalonsoa dalonsoa requested review from Copilot, dc2917 and tsmbland and removed request for Copilot July 9, 2026 13:37
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.44%. Comparing base (0600774) to head (98cdc54).

Files with missing lines Patch % Lines
src/output.rs 83.33% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1405      +/-   ##
==========================================
+ Coverage   89.42%   89.44%   +0.01%     
==========================================
  Files          59       59              
  Lines        8367     8381      +14     
  Branches     8367     8381      +14     
==========================================
+ Hits         7482     7496      +14     
  Misses        564      564              
  Partials      321      321              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tsmbland tsmbland left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one small comment

Comment thread src/output.rs
// If the unmet demand writer already exist, we return with an error, as it should not happen
ensure!(
self.unmet_demand_writer.is_none(),
"Unmet demand file already exists!"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not possible for a user to trigger this, it should panic rather than returning an error

Copilot AI review requested due to automatic review settings July 10, 2026 10:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts debug output generation so debug_unmet_demand.csv is only created when unmet demand is actually present, avoiding an always-empty debug file in normal successful runs.

Changes:

  • Refactors DebugDataWriter to store the unmet-demand file path and make the unmet-demand CSV writer optional (lazy creation).
  • Updates unmet-demand writing logic to no-op when there are no rows, and updates flushing to handle the optional writer.
  • Updates regression test data for the simple case by removing the previously committed empty debug_unmet_demand.csv.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/output.rs Lazily creates and conditionally flushes the unmet-demand debug CSV writer to avoid producing an empty file.
tests/data/simple/debug_unmet_demand.csv Removes the committed empty debug output file from regression test data.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/output.rs
Comment on lines +444 to +457
let rows: Vec<(&CommodityID, &RegionID, &TimeSliceID, Flow)> =
iter.collect::<Vec<(&CommodityID, &RegionID, &TimeSliceID, Flow)>>();

if rows.is_empty() {
return Ok(());
}

// If the unmet demand writer already exist, we return with an error, as it should not happen
if self.unmet_demand_writer.is_some() {
panic!("Unmet demand file already exists!");
}

self.unmet_demand_writer = Some(csv::Writer::from_path(&self.unmet_demand_file_path)?);
for (commodity_id, region_id, time_slice, value) in rows {
Comment thread src/output.rs
Comment on lines 470 to 472
}

Ok(())
Comment thread src/output.rs
self.unmet_demand_writer.serialize(row)?;
self.unmet_demand_writer
.as_mut()
.expect("Writer does not exist (cannot not happen)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty debug_unmet_demand.csv file always created if debug_model==true

3 participants